package com.example.myapplication;

import com.everyline.baselibrary.base.RxPresenter;
import com.everyline.baselibrary.http.RxHelper;

import java.util.Map;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;

/**
 * crated by Administrator on 2021/6/3
 * 746608431@qq.com
 * 描述：TODO
 */
public class TestPresenter extends RxPresenter<TestContract.View> implements TestContract.Presenter {


    @Override
    public void applogin(Map<String, String> map) {
        RetrofitUtils.getApiUrl().applogin(map)
                .compose(RxHelper.rxSchedulerHelper())
                .compose(RxHelper.handleMyResultString())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        mView.showapplogin(s);

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.showError(throwable);
                    }
                });

    }

    @Override
    public void applogin2(Map<String, String> map) {
        RetrofitUtils.getApiUrl().applogin2(map)
                .compose(RxHelper.rxSchedulerHelper())
                .compose(RxHelper.handleMyResult())
                .subscribe(new Consumer<LoginBean>() {
                    @Override
                    public void accept(LoginBean loginBean) throws Exception {
                        mView.showapplogin2(loginBean);
                    }
                });

    }

    @Override
    public void tousupaotuiorder(Map<String, RequestBody> map) {
        Disposable disposable = RetrofitUtils.getApiUrl()
                .tousupaotuiorder(map)
                .compose(RxHelper.handleMyResultString())
                .compose(RxHelper.rxSchedulerHelper())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String string) throws Exception {

                        mView.showapplogin(string);

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                        mView.showError(throwable);
                    }
                });


        addSubscribe(disposable);
    }
}
